[LIBXC] Clean up use of sterror(). Define a thread-safe
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 8 Dec 2006 11:57:06 +0000 (11:57 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 8 Dec 2006 11:57:06 +0000 (11:57 +0000)
version which uses strerror_r(), and tries to cope with
the POSIX and GNU versions of that function.
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/ia64/xc_ia64_linux_save.c
tools/libxc/xc_core.c
tools/libxc/xc_linux_build.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h

index 42ec21c8027f1667a9797c800139c03b25f6dfc8..d98725445aac0417cf50aaf7af964a75f36c2950 100644 (file)
@@ -353,7 +353,7 @@ xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
                    It will be remarked dirty.
                    FIXME: to be tracked.  */
                 fprintf(stderr, "cannot map page %lx: %s\n",
-                        page_array[N], strerror (errno));
+                        page_array[N], safe_strerror(errno));
                 continue;
             }
 
index 550d5691e1d843fd7310ad86123c6a02b7a94b42..035bf301e5d40a93ed330eebadd6225faf216c3b 100644 (file)
@@ -140,7 +140,7 @@ static int local_file_dump(void *args, char *buffer, unsigned int length)
         bytes = write(da->fd, &buffer[offset], length-offset);
         if ( bytes <= 0 )
         {
-            PERROR("Failed to write buffer: %s", strerror(errno));
+            PERROR("Failed to write buffer");
             return -errno;
         }
     }
@@ -158,7 +158,7 @@ xc_domain_dumpcore(int xc_handle,
 
     if ( (da.fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 )
     {
-        PERROR("Could not open corefile %s: %s", corename, strerror(errno));
+        PERROR("Could not open corefile %s", corename);
         return -errno;
     }
 
index edf95c0fc09368035f61defa295f9c55c99f1af5..a2b5274083aa4fe9001c394b980cbf1d49c6781e 100644 (file)
@@ -593,8 +593,8 @@ static int setup_guest(int xc_handle,
     /* shared_info page starts its life empty. */
     shared_info = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame);
-    printf("shared_info = %p, err=%s frame=%lx\n",
-           shared_info, strerror (errno), shared_info_frame);
+    printf("shared_info = %p frame=%lx\n",
+           shared_info, shared_info_frame);
     //memset(shared_info, 0, PAGE_SIZE);
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
index 3ff0b791d00f659769f60eebcb16071023a3520f..ed76cf003c2887b88dfe540e28104ae18639389d 100644 (file)
@@ -483,6 +483,19 @@ unsigned long xc_make_page_below_4G(
     return new_mfn;
 }
 
+char *safe_strerror(int errcode)
+{
+    static __thread char errbuf[32];
+#ifdef __GLIBC__
+    /* Broken GNU definition of strerror_r may not use our supplied buffer. */
+    return strerror_r(errcode, errbuf, sizeof(errbuf));
+#else
+    /* Assume we have the POSIX definition of strerror_r. */
+    strerror_r(errcode, errbuf, sizeof(errbuf));
+    return errbuf;
+#endif
+}
+
 /*
  * Local variables:
  * mode: C
index f087e7de6987f23fb6eda76dab87414753cf2e2b..6dfbdead7af39ddae8d20c6ef145d43dd9f10a4f 100644 (file)
 #define PPRINTF(_f, _a...)
 #endif
 
+char *safe_strerror(int errcode);
 void xc_set_error(int code, const char *fmt, ...);
 
 #define ERROR(_m, _a...)  xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
-                                       ## _a , errno, strerror(errno))
+                                       ## _a , errno, safe_strerror(errno))
 
 int lock_pages(void *addr, size_t len);
 void unlock_pages(void *addr, size_t len);